<template>
    <div>
        <van-cell class="summary">
            <van-row>
                <van-col span="12">总分：{{ templateInfo.TemplateScore }}</van-col>
                <van-col span="12">自评得分：<span v-if="searchEntity.SelfScore < templateInfo.TemplateScore" class="c-red">{{ searchEntity.SelfScore }}</span>
                    <span v-if="searchEntity.SelfScore >= templateInfo.TemplateScore" class="c-green">{{ searchEntity.SelfScore }}</span>
                </van-col>
            </van-row>
            <van-row>
                <van-col span="12">考评最终得分：<span v-if="!searchEntity.OverScore">{{
            "未出"
          }}</span>
                    <span v-if="searchEntity.OverScore < templateInfo.TemplateScore" class="c-red">{{ searchEntity.OverScore }}</span>
                    <span v-if="!searchEntity.OverScore >= templateInfo.TemplateScore" class="c-green">{{ searchEntity.OverScore }}</span>
                </van-col>
            </van-row>
        </van-cell>
        <div id="divApp" class="check-list">
            <van-collapse v-model="activeNames">
                <van-divider v-show="showTarget" dashed>考核项</van-divider>
                <template v-for="(item, index) in listProject">
                    <van-collapse-item v-bind:name="index + 1" v-bind:key="index" icon="coupon-o">
                        <template #title>
                            <div class="checklist-title">
                                {{ item.AssessmentTarget }}
                            </div>
                        </template>
                        <div v-bind:key="index" id="divList">
                            <template v-for="(itemGns, indexGns) in item.Grandsons">
                                <div style="margin-bottom: 10px; padding-bottom: 10px" v-bind:key="indexGns">
                                    <van-field label-width="60px" v-bind:value="itemGns.ItemNo" style="display: none"></van-field>
                                    <van-row>
                                        <van-col span="24">
                                            <span class="spanPoint">
                                                {{ indexGns + 1 }}、{{ itemGns.GradingPoint }}（{{
                          itemGns.Score
                        }}分）
                                            </span>
                                        </van-col>
                                    </van-row>
                                    <van-row>
                                        <van-col span="24">
                                            <span> 评分标准：{{ itemGns.GradingStandard }} </span>
                                        </van-col>
                                    </van-row>
                                    <van-row>
                                        <van-col span="24">
                                            <span>自评得分：{{ itemGns.SelfList[0].Score }}</span>
                                        </van-col>
                                    </van-row>
                                    <van-row>
                                        <van-col span="24">
                                            <span>加扣分说明：{{
                          itemGns.SelfList[0].DeductRemark
                        }}</span>
                                        </van-col>
                                    </van-row>
                                    <van-row v-if="itemGns && itemGns.SelfList[0].Attachs">
                                        <van-col span="24">
                                            <div id="divFile2">
                                                <file-list-read-only :attachs="itemGns.SelfList[0].Attachs" :labelName="'自评附件：'"></file-list-read-only>
                                            </div>
                                        </van-col>
                                    </van-row>
                                    <div v-for="itemGnsOther in itemGns.OtherList" v-show="itemGns.OtherList.length > 0">
                                        <van-row>
                                            <van-col span="12">
                                                <span>考评人：{{ itemGnsOther.UserOrDept }}</span>
                                            </van-col>
                                            <van-col span="12">
                                                <span>考评得分：{{ itemGnsOther.Score || "未考评" }}</span>
                                            </van-col>
                                        </van-row>
                                        <van-row>
                                            <van-col span="24">
                                                <span>加扣分说明：{{ itemGnsOther.DeductRemark }}</span>
                                            </van-col>
                                        </van-row>
                                    </div>
                                </div>
                                <van-divider></van-divider>
                            </template>
                        </div>
                    </van-collapse-item>
                </template>
                <van-divider v-show="showTarget" dashed>指标项</van-divider>
                <template v-for="(itemTarget, indexTarget) in listTarget" v-show="showTarget">
                    <van-collapse-item v-bind:name="itemTarget.IndexName" v-bind:key="itemTarget.ItemNo">
                        <template #title>
                            <img class="title-logo" src="@/assets/Images/AppIcon/fragment_noticetype_3.png" alt />
                            {{ itemTarget.IndexName }}
                        </template>
                        <div v-bind:key="indexTarget">
                            <van-row>
                                <van-col span="12">
                                    <span>分数：{{ itemTarget.Score }}</span>
                                </van-col>
                            </van-row>
                            <van-row>
                                <van-col span="24">
                                    <span>评分标准：{{ itemTarget.GradingStandard }}</span>
                                </van-col>
                            </van-row>
                            <van-row>
                                <van-col span="24"><span>指标值：{{ itemTarget.SelfList[0].CalculateValue }}</span></van-col>
                            </van-row>
                            <van-row>
                                <van-col span="24"><span>自评得分：{{ itemTarget.SelfList[0].Score }}</span></van-col>
                            </van-row>
                            <van-row>
                                <van-col span="24"><span>加扣分说明：{{ itemTarget.SelfList[0].DeductRemark }}</span></van-col>
                            </van-row>
                            <van-row v-if="itemTarget && itemTarget.SelfList[0].Attachs">
                                <van-col span="24">
                                    <div id="divFile2">
                                        <file-list-read-only :attachs="itemTarget.SelfList[0].Attachs" :labelName="'自评附件：'"></file-list-read-only>
                                    </div>
                                </van-col>
                            </van-row>
                            <div v-for="itemTargetOther in itemTarget.OtherList">
                                <van-row>
                                    <van-col span="12">
                                        <span>考评人：{{ itemTargetOther.UserOrDept }}</span>
                                    </van-col>
                                    <van-col span="12">
                                        <span>考评得分：{{ itemTargetOther.Score }}</span>
                                    </van-col>
                                </van-row>
                                <van-row>
                                    <van-col span="24">
                                        <span> 加扣分说明：{{ itemTargetOther.DeductRemark }}</span>
                                    </van-col>
                                </van-row>
                            </div>
                        </div>
                    </van-collapse-item>
                </template>
            </van-collapse>
        </div>
    </div>
</template>
<script>
import { findTaskByID, selfUpdate } from "@/api/ZXTFAchievements";
import FileListReadOnly from "../../../components/Attach/FileListReadOnly.vue";
import FileList from "@/components/FileList/FileList.vue";
import Enclosure from "@/components/Enclosure/Enclosure.vue";
import { uploadAttach } from "@/api/common";
export default {
    components: {
        Enclosure,
        FileList,
        FileListReadOnly,
    },
    data() {
        return {
            baseUrl: process.env.VUE_APP_BASE_API,
            filePopup: false,
            fileList: [],
            showEnclosure: false,
            List: [],
            searchEntity: { SelfScore: null },
            templateInfo: { TemplateScore: null, StandardScore: null },
            listProject: null,
            listTarget: null,
            show: false,
            activeNames: ["1"],
            id: this.$route.query.ID,
            currentItemNo: null,
            fileType: null,
            attachs: null,
            showTarget: false,
        };
    },
    created() {
        if (this.$route.query.ID) {
            this.getDetail();
        }
    },
    computed: {},
    methods: {
        setCurrentID(itemNo, fileType) {
            this.currentItemNo = itemNo;
            this.fileType = fileType;
            this.fileOperate();
        },
        _fileUploadCb(attachs) {
            var vm = this;
            //this.form.Attach = attachs;
            vm.attachs = attachs;
            vm.fileOperate();
        },
        fileOperate() {
            var vm = this;
            if (vm.attachs != null) {
                if (vm.fileType == "gns") {
                    for (var i = 0; i < vm.listProject.length; i++) {
                        for (
                            var j = 0;
                            j < vm.listProject[i].Grandsons.length;
                            j++
                        ) {
                            if (
                                vm.listProject[i].Grandsons[j].ItemNo ==
                                vm.currentItemNo
                            ) {
                                vm.listProject[i].Grandsons[
                                    j
                                ].SelfList[0].Attachs = vm.attachs;
                            }
                        }
                    }
                } else {
                    for (var i = 0; i < vm.listTarget.length; i++) {
                        if (vm.listTarget[i].ItemNo == vm.currentItemNo) {
                            vm.listTarget[i].SelfList[0].Attachs = vm.attachs;
                        }
                    }
                }
            }
        },
        getDetail() {
            var me = this;
            let params = { ID: this.id, type: 1 };
            findTaskByID(params).then((res) => {
                if (res != null && res.data != null) {
                    me.searchEntity = res.data;
                    me.templateInfo = res.data.TemplateInfo;
                    me.listProject = res.data.TemplateInfo.Details;
                    me.listTarget = res.data.TemplateInfo.Details2;
                    if (me.listTarget != null && me.listTarget.length > 0) {
                        me.showTarget = true;
                    } else {
                        me.showTarget = false;
                    }
                }
            });
        },
        validator(val) {
            return true;
        },

        buttonSave(index) {
            var vm = this;
            var params = {};
            var saveProject = [];
            params.Details = [];
            params.Details3 = [];

            if (index == 1) {
                params.IsPublish = true;
                //  alert("提交");
            } else {
                params.IsPublish = false;
                //  alert("暂存");
            }
            params.ID = vm.searchEntity.ID;
            for (var i = 0; i < vm.listProject.length; i++) {
                for (var j = 0; j < vm.listProject[i].Grandsons.length; j++) {
                    var tempDetailPro = {};
                    tempDetailPro.Code = vm.listProject[i].Grandsons[j].ItemNo;
                    tempDetailPro.Score =
                        vm.listProject[i].Grandsons[j].SelfList[0].Score;
                    if (!tempDetailPro.Score) {
                        return this.$toast(
                            "请输入【" +
                                vm.listProject[i].AssessmentTarget +
                                vm.listProject[i].Grandsons[j].GradingPoint +
                                "】的自评得分"
                        );
                    }
                    if (
                        tempDetailPro.Score >
                        vm.listProject[i].Grandsons[j].Score
                    ) {
                        return this.$toast("自评得分不能大于模板分数");
                    }

                    tempDetailPro.DeductRemark =
                        vm.listProject[i].Grandsons[j].SelfList[0].DeductRemark;
                    tempDetailPro.Attachs =
                        vm.listProject[i].Grandsons[j].SelfList[0].Attachs;
                    params.Details.push(tempDetailPro);
                }
            }

            for (var i = 0; i < vm.listTarget.length; i++) {
                var tempDetailTarget = {};
                tempDetailTarget.Code = vm.listTarget[i].ItemNo;
                tempDetailTarget.CalculateValue =
                    vm.listTarget[i].CalculateValue;
                tempDetailTarget.Score = vm.listTarget[i].SelfList[0].Score;
                if (!tempDetailTarget.Score) {
                    return this.$toast(
                        "请输入【" + vm.listTarget[i].IndexName + "】的自评得分"
                    );
                }
                if (tempDetailTarget.Score > vm.listTarget[i].Score) {
                    return this.$toast(
                        "【" +
                            vm.listTarget[i].IndexName +
                            "】自评得分不能大于模板分数"
                    );
                }
                tempDetailTarget.DeductRemark =
                    vm.listTarget[i].SelfList[0].DeductRemark;
                tempDetailTarget.Attachs = vm.listTarget[i].SelfList[0].Attachs;
                params.Details3.push(tempDetailTarget);
            }
            //自评
            selfUpdate(params).then((res) => {
                if (params.IsPublish) {
                    this.$toast.success("自评成功");
                } else {
                    this.$toast.success("保存成功");
                }
                this.$router.goRefresh();
            });
        },
    },
};
</script>

<style lang="less" scoped>
#divFile div {
    color: #646566;
}
#divFile2 > div {
    line-height: 30px;
}
#divFile2 div {
    color: #646566;
}
#divFileUpload .van-cell,
#divFileUpload1 .van-cell {
    background-color: transparent;
}

#divApp .spanPoint {
    font-size: 15px;
    color: black;
}

#divApp span {
    color: #646566;
    font-size: 14px;
    line-height: 28px;
}
.van-col {
    vertical-align: middle;
}

.van-cell::after {
    border-bottom: 0px;
}
.van-field__label {
    width: 1.8rem;
    margin-right: 0px;
}
.total-count {
    display: flex;
    align-items: center;
}
.check-list {
    min-height: 100vh;
    padding-bottom: 100px;
    background-color: #e8f1f8;
}
.checklist-title {
    display: flex;
    align-items: center;
}
.title-logo {
    width: 15px;
    height: 16px;
    margin-right: 10px;
}
// 符合按钮
.accord-btns {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .accord-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 30%;
        height: 22px;
        background-color: #fff;
        color: #666;
        font-size: 12px;
    }
    .active {
        background-color: #1989fa;
        color: #fff;
    }
    .inconformity {
        background-color: #ee0a24;
        color: #fff;
    }
    .not-applicable {
        background-color: #ff976a;
        color: #fff;
    }
}
.inconformity-list {
    background-color: #fff;
    margin-top: 10px;
    padding-top: 10px;
}
/*
        .main {
            height: 100vh;
        }
    */

.det_top_box {
    padding: 10px;
    background-color: #e8f1f8;
}

.detail_header {
    color: #ffffff;
    background: url("../../../assets/Images/AppIcon/image_riskunit_detail_bg.png");
    background-size: cover;
    padding: 10px;
    border-radius: 5px;
    /*background-color: #fff;*/
}
.det_tab {
    padding: 10px;
    .det_tab_item {
        padding: 10px 0;
        background-color: #fff;
        border-radius: 5px;
        margin-bottom: 10px;

        .det_tab_item_text {
            padding: 0 10px;
        }
    }
}

.text_img {
    display: flex;
    align-items: center;

    .img_item {
        width: 33.3%;
        text-align: center;

        img {
            height: 25px;
            width: 25px;
            margin-bottom: 10px;
        }
    }
}

.text_total_img {
    display: flex;
    align-items: center;

    .img_item {
        width: 33.3%;
        text-align: center;

        .img_item_top {
            display: flex;
            vertical-align: middle;
            margin-bottom: 10px;
        }
        img {
            height: 15px;
            width: 15px;
            margin-right: 5px;
        }
    }
}

.bottom-buttons {
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    .submit-button,
    .save-btn {
        border: none;
        border-radius: 0;
    }
    .submit-button {
        width: 70%;
    }
    .save-btn {
        width: 30%;
    }
}
.van-divider {
    border-color: #ccc;
}
</style>

<style lang="less" scoped>
.check-list {
    padding-top: 1.8rem;
    .van-collapse {
        .van-collapse-item__content {
            background-color: #e8f1f8;
            padding: 10px 10px 10px 10px;
        }
    }
}

.summary {
    position: fixed;
    top: 1.2rem;
    z-index: 100;
}
</style>
